package ntd.util.frame.action.database;

import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONUtil;
import com.c.opt.ComOpt;
import com.ToolOpt;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.util.frame.action.database.factory.FactoryTableBuild;

import java.util.Map;

public class ActionTableSync extends ActionAbs {

    @Override
    public ActionInfo info() {
        return new ActionInfo("数据同步", "action-table-sync", new ActionTableSync());
    }

    @Override
    public ActionOutBo handle() {
        
        ComOpt<Object> comOpt = ToolOpt.get(actionInBo.getDataCode(), actionInBo.dsId());

        Map<String, Object> map = MapUtil.map(actionInBo.getData(), (s, s2) -> s2);

        // 扩展逻辑执行
        FactoryTableBuild.extHandle(actionInBo.getDataCode(), map);

        String id = comOpt.sync(map);

        return new ActionOutBo(comOpt.getById(id));
    }
}
